package cn.edu.hqu.exp.courseselection.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import lombok.Data;

@Data
@Entity
@Table(name="personinfo_electionform")
public class PersonInfo {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	private Date placedAt;
	@Size(min=10,max=10,message="学号必须填入10位")
	public String stuNo;
	@NotBlank(message="姓名不能为空")
	public String stuName;
	@NotBlank(message="班级不能为空")
	public String stuClass;
	@NotBlank(message="学院不能为空")
	public String  stuCollege;
	@ManyToMany(targetEntity = ElectionForm.class)
	private List<ElectionForm> elections = new ArrayList<>();
	@ManyToOne
	private User user;
	public void addElectionForm(ElectionForm eletion) {
		this.elections.add(eletion);
	}
	@PrePersist
	void placeAt() {
		this.placedAt=new Date();
	}
}
